# -*- coding: utf-8 -*-
import data_comm
import pymysql

# 打开数据库连接
connection = pymysql.connect(host = '',
                            user = '',
                            password = '',
                            db = '',
                            charset = 'utf8')

# 使用 cursor() 方法创建一个游标对象 cursor
cursor = connection.cursor()

result = []

# 将社区中作者的所有兴趣从数据库中取出来，然后进行统计。留下
for comm in data_comm.data:
    # 获取作者的名字列表
    comm_key = list(comm.keys())
    print(comm_key)

    comm_interest_list = []

    arg_list = ','.join(['%s'] * len(comm_key))
    sql = "SELECT a_xingqu FROM author_info where a_name in (%s)"%arg_list
    # print(sql)

    # 使用 execute()  方法执行 SQL 查询 
    cursor.execute(sql,comm_key)
    xingqu_list = cursor.fetchall()
    for xingqu in xingqu_list:
        xingqu = xingqu[0]
        comm_interest_list.append(xingqu)
    
    result.append(comm_interest_list)

connection.close()
fd = open("interest.txt",'w')
print(result,file = fd)
fd.close()
